package com.wonders.hisdoctor.station.project.treat.controller;

import com.wonders.his.common.bean.BaseResult;
import com.wonders.his.common.exception.CustomException;
import com.wonders.his.common.utils.StringUtils;
import com.wonders.hisdoctor.station.project.base.domain.OutpTreatRec;
import com.wonders.hisdoctor.station.project.treat.service.ITreatService;
import com.wonders.hisdoctor.station.project.treat.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * @author zhaogongming
 * @date 2021.2.23 下午 7:14 星期二
 * @desc: 治疗申请_Controller
 */
@RestController
@RequestMapping("treat")
@Api(tags = "治疗申请")
public class TreatController {

    @Autowired
    private ITreatService treatService;

    /**
     * 项目选择_左列表
     * @param hospitalCode
     * @return
     */
    @ApiOperation("项目选择_左列表")
    @GetMapping("queryDept")
    public BaseResult<List<DeptVo>> queryDept(@RequestParam("hospitalCode") String hospitalCode) {
        List<DeptVo> deptVos = treatService.queryDept(hospitalCode);
        return BaseResult.success(deptVos);
    }

    /**
     * 项目选择_列表
     * @param hospitalCode
     * @param itemName 组合名称
     * @param deptCode
     * @return
     */
    @ApiOperation("项目选择_列表")
    @GetMapping("itemList")
    public BaseResult<List<ItemListVo>> itemList(String hospitalCode, String itemName, String deptCode) {
        if (StringUtils.isEmpty(hospitalCode)) {
            throw new CustomException("机构编码不能为空");
        }
        List<ItemListVo> itemList = treatService.itemList(hospitalCode, itemName, deptCode);
        return BaseResult.success(itemList);
    }

    /**
     * 提交申请_保存
     * @param treatVo
     * @return
     */
    @ApiOperation("提交申请_保存")
    @PostMapping("save")
    public BaseResult<Integer> save(@RequestBody TreatVo treatVo) {
        return BaseResult.success(treatService.saveNew(treatVo));
    }

    /**
     * 治疗申请_列表
     */
    @ApiOperation("治疗申请_列表")
    @GetMapping("queryTreatList")
    public BaseResult<List<QueryTreatVo>> queryTreatList(@DateTimeFormat(pattern = "yyyy-MM-dd") Date visitDate,
                                                         String patientId, Integer visitNo, String empNo) {
        if (StringUtils.isEmpty(patientId)) {
            throw new CustomException("请在就诊队列选择就诊患者!");
        }
        return BaseResult.success(treatService.queryTreatList(visitDate, patientId, visitNo, empNo));
    }

    /**
     * 历史申请_查询
     */
    @ApiOperation("历史申请_查询")
    @PostMapping("queryHistory")
    public BaseResult<List<HistoryTreatVo>> queryHistory(@RequestBody QueryHistoryVo queryHistoryVo) {
        return BaseResult.success(treatService.queryHistory(queryHistoryVo));
    }

    /**
     * 撤销申请_删除
     */
    @ApiOperation("撤销申请_删除")
    @PostMapping("delete")
    public BaseResult<Integer> delete(@RequestBody List<OutpTreatRec> outpTreatRecs) {
        return BaseResult.success(treatService.delete(outpTreatRecs));
    }

    /**
     * 治疗申请单_打印
     */
    @ApiOperation("治疗申请单_打印")
    @PostMapping("treatPrint")
    public BaseResult<TreatApplicationFormVo> treatPrint(@RequestBody List<TreatPrintNewVo> treatPrintVo) {
        return BaseResult.success(treatService.treatPrint(treatPrintVo));
    }

    /**
     * 保存并打印
     */
    @ApiOperation("保存并打印")
    @PostMapping("saveAndPrint")
    public BaseResult<TreatApplicationFormVo> saveAndPrint(@RequestBody TreatVo treatVo,HttpServletRequest request){
        return BaseResult.success(treatService.saveAndPrintNew(treatVo,request));
    }

    /**
     * 存为套餐_保存
     */
    @ApiOperation("存为套餐_保存")
    @PostMapping("saveSetMeal")
    public BaseResult<Integer> saveSetMeal(@RequestBody SetMealVo setMealVo) {
        int num = treatService.saveSetMeal(setMealVo);
        return BaseResult.success(num);
    }
}
